package com.hanhanxiaochong.zhongxiangchuanmei.presenter;

import com.hanhanxiaochong.zhongxiangchuanmei.bean.ProjectEvaluationListBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.base.BasePresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IEvaluationListView;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseApi;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by rockphoenix on 2018/7/16.
 */

public class EvaluationListPresenter extends BasePresenter<IEvaluationListView> {

    public EvaluationListPresenter(IEvaluationListView iView) {
        super(iView);
    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi) {

    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi, int state) {

    }

    public void getProductEvaluationList(String p_id) {
        iView.showLoadingDialog();
        addSubscription(RetrofitSource.createApi(HttpPostService.class)
                .prod_comment(p_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<ProjectEvaluationListBean>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<ProjectEvaluationListBean> response) {
                        iView.setProductEvaluationList(response.getData());
                    }
                }));
    }

    public void getProjectEvaluationList(String p_id) {
        iView.showLoadingDialog();
        addSubscription(RetrofitSource.createApi(HttpPostService.class)
                .proj_comment(p_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<ProjectEvaluationListBean>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<ProjectEvaluationListBean> response) {
                        iView.setProjectEvaluationList(response.getData());
                    }
                }));
    }
}
